import { defineStore } from 'pinia'

// 定义类型接口
interface RechargeOrderData {
  id: string | number
  [key: string]: any
}

interface CreditRepaymentOrder {
  id: string | number
  pay_status: number
  pay_money: number
  name: string
  user_name: string
  create_time: string
  pay_list_text: string
  clerk: {
    user_name: string
  }
  [key: string]: any
}

interface HandOverOrder {
  id: string | number
  [key: string]: any
}

interface DishItem {
  id: string | number
  [key: string]: any
}

interface OrderState {
  // 当前选中的充值记录订单中当行表格的数据
  selectRechargeOrderData: RechargeOrderData | null
  // 当前选中的回款明细订单中当行表格的数据
  selectCreditRepaymentOrder: CreditRepaymentOrder | null
  // 当前选中的交班订单中当行表格的数据
  selectHandOverOrder: HandOverOrder | null
  // 当前待上菜的菜品列表
  selectDishList: DishItem[]
}

export const useOrderStore = defineStore('order', {
  state: (): OrderState => ({
    // 当前选中的充值记录订单中当行表格的数据
    selectRechargeOrderData: null,
    // 当前选中的回款明细订单中当行表格的数据
    selectCreditRepaymentOrder: null,
    // 当前选中的交班订单中当行表格的数据
    selectHandOverOrder: null,
    // 当前待上菜的菜品列表
    selectDishList: []
  }),
  
  getters: {
    // 获取当前选中的充值记录订单数据
    getSelectRechargeOrderData: (state): RechargeOrderData | null => state.selectRechargeOrderData,
    // 获取当前选中的回款明细订单数据
    getSelectCreditRepaymentOrder: (state): CreditRepaymentOrder | null => state.selectCreditRepaymentOrder,
    // 获取当前选中的交班订单数据
    getSelectHandOverOrder: (state): HandOverOrder | null => state.selectHandOverOrder,
    // 获取当前待上菜的菜品列表
    getSelectDishList: (state): DishItem[] => state.selectDishList
  },
  
  actions: {
    // 更新当前选中的充值记录订单当行表格的数据
    updateSelectRechargeOrderData(val: RechargeOrderData | null): void {
      this.selectRechargeOrderData = val
    },
    // 更新当前选中的回款明细订单当行表格的数据
    updateSelectCreditRepaymentOrder(val: CreditRepaymentOrder | null): void {
      this.selectCreditRepaymentOrder = val
    },
    // 更新当前选中的交班订单中当行表格的数据
    updateSelectHandOverOrder(val: HandOverOrder | null): void {
      this.selectHandOverOrder = val
    },
    // 添加当前待上菜的菜品列表
    updateSelectDishList(val: DishItem[]): void {
      this.selectDishList = val
    }
  }
})
